//implement TINYToken

#include "TINYToken.h"

TINYToken::TINYToken()
{
}

TINYToken::~TINYToken()
{
}

void TINYToken::addCharactor(const char &ch)
{
    m_tokenString += ch;
}

void TINYToken::setTokenType(TOKENTYPE type)
{
    m_type = type;
}


//---------------------implement TINYSpecialSymTable--------------

TINYSpecialSymTable TINYSpecialSymTable::_symTable;

struct SymPair
{
    char sym;
    TINYToken::TOKENTYPE type;
} SPLSYMBOL[] = { {'+', TINYToken::PLUS}, {'-', TINYToken::MINUS}, {'*', TINYToken::TIMES},
{'/', TINYToken::OVER},  {'=', TINYToken::EQ}, {'<', TINYToken::LT},
{'(', TINYToken::LPAREN}, {')', TINYToken::RPAREN}, {';', TINYToken::SEMT}};

TINYSpecialSymTable::TINYSpecialSymTable()
{
    m_tokenMap = new GHashMap<char, TINYToken::TOKENTYPE>();
    for (int i = 0; i < sizeof(SPLSYMBOL) / sizeof(char); ++i)
        m_tokenMap->insert(SPLSYMBOL[i].sym, SPLSYMBOL[i].type);
}

TINYSpecialSymTable::~TINYSpecialSymTable()
{
    if (m_tokenMap != 0)
        delete m_tokenMap;
}

const TINYSpecialSymTable& TINYSpecialSymTable::instance()
{
    return _symTable;
}

TINYToken::TOKENTYPE TINYSpecialSymTable::getTokenType(const char &ch)
{
    GMap<char, TINYToken::TOKENTYPE>::IterPtr iter(m_tokenMap->find(ch));
    if (iter != m_tokenMap->end())
        return iter->getValue();
    return TINYToken::NONE;
}
